package com.atguigu.eduservice.config;

import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector;
import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Configuration
@MapperScan("com.atguigu.eduservice.mapper")
public class EduConfig {
    @Bean//注册乐观锁插件
    public OptimisticLockerInterceptor optimisticLockerInterceptor(){
        return new OptimisticLockerInterceptor();
    }

    //分页查询
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }

    //逻辑删除组件
    @Bean
    public ISqlInjector sqlInjector(){
        return  new LogicSqlInjector();
    }

    //mybatis-plus3.2以上版本移除了性能分析插件
    //Sql执行效率插件
    @Bean
    @Profile({"dev","test"})//设置开启环境
    public PerformanceInterceptor performanceMonitorInterceptor(){
        PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
        performanceInterceptor.setFormat(true);//设置SQL的格式
        //performanceInterceptor.setMaxTime(1000);//设置SQL语句执行的最大时间，默认单位是ms
        return performanceInterceptor;
    }
}
